<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";
import { usePublicHooks } from "@/views/common/hooks";
const selectedOptions = ref(["120000", "120100", "120101"]);
import {
  provinceAndCityDataPlus,
  provinceAndCityData,
  convertTextToCode,
  regionDataPlus,
  regionData,
  CodeToText
} from "@/utils/chinaArea";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    title: "新增",
    username: "",
    password: "",
    status: 1
  })
});

const sexOptions = [
  {
    value: 0,
    label: "男"
  },
  {
    value: 1,
    label: "女"
  }
];
const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="100px"
  >
    <el-row :gutter="30">
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="newFormInline.username"
          clearable
          placeholder="请输入用户昵称"
        />
      </el-form-item>
    </el-row>
    <el-row :gutter="30">
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="newFormInline.mobile"
          clearable
          placeholder="请输入手机号"
          maxlength="11"
        />
      </el-form-item>
    </el-row>
    <el-row v-if="newFormInline.title === '新增'" :gutter="30">
      <el-form-item label="用户密码" prop="password">
        <el-input
          v-model="newFormInline.password"
          type="password"
          clearable
          placeholder="请输入用户密码"
        />
      </el-form-item>
    </el-row>
    <el-row :gutter="30">
      <el-form-item label="到期时间" prop="expires">
        <el-date-picker
          v-model="newFormInline.expires"
          type="datetime"
          placeholder="请选择到期时间"
          format="YYYY/MM/DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </el-form-item>
    </el-row>

    <el-row :gutter="30">
      <el-form-item label="地区" prop="region">
        <el-cascader v-model="newFormInline.region" :options="regionData" />
      </el-form-item>
    </el-row>

    <el-row :gutter="30">
      <el-form-item label="详细地址" prop="address">
        <el-input v-model="newFormInline.address" />
      </el-form-item>
    </el-row>

    <el-row :gutter="30">
      <el-form-item label="用户状态" prop="status">
        <el-switch
          v-model="newFormInline.status"
          inline-prompt
          :active-value="1"
          :inactive-value="0"
          active-text="启用"
          inactive-text="停用"
          :style="switchStyle"
        />
      </el-form-item>
    </el-row>
  </el-form>
</template>
